package com.ruoyi.training.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.ruoyi.training.dto.FrontSubmitDto;
import com.ruoyi.training.dto.RecordsUploadProcessDto;
import com.ruoyi.training.dto.RecordsUploadSupplementDto;
import com.ruoyi.training.vo.RecordsUploadProcessVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.Records;
import com.ruoyi.training.service.IRecordsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 档案Controller
 *
 * @author ruoyi
 * @date 2025-09-18
 */
@RestController
@RequestMapping("/records")
public class RecordsController extends BaseController
{
    @Autowired
    private IRecordsService recordsService;

    /**
     * 查询档案列表
     */
    @RequiresPermissions("training:records:list")
    @GetMapping("/list")
    public TableDataInfo list(Records records)
    {
        startPage();
        List<Records> list = recordsService.selectRecordsList(records);
        return getDataTable(list);
    }

    /**
     * 导出档案列表
     */
    @RequiresPermissions("training:records:export")
    @Log(title = "档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Records records)
    {
        List<Records> list = recordsService.selectRecordsList(records);
        ExcelUtil<Records> util = new ExcelUtil<Records>(Records.class);
        util.exportExcel(response, list, "档案数据");
    }

    /**
     * 获取档案详细信息
     */
    @RequiresPermissions("training:records:query")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") String recordId)
    {
        return success(recordsService.selectRecordsByRecordId(recordId));
    }

    /**
     * 新增档案
     */
    @RequiresPermissions("training:records:add")
    @Log(title = "档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Records records)
    {
        return toAjax(recordsService.insertRecords(records));
    }

    /**
     * 修改档案
     */
    @RequiresPermissions("training:records:edit")
    @Log(title = "档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Records records)
    {
        return toAjax(recordsService.updateRecords(records));
    }

    /**
     * 删除档案
     */
    @RequiresPermissions("training:records:remove")
    @Log(title = "档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable String[] recordIds)
    {
        return toAjax(recordsService.deleteRecordsByRecordIds(recordIds));
    }

    /**
     * 处理上传资料
     * lqx
     */
//    @RequiresPermissions("training:records:upload-process")
    @Log(title = "处理上传资料", businessType = BusinessType.OTHER)
    @PostMapping("/upload-process")
    public RecordsUploadProcessDto recordsUploadProcess(@RequestBody RecordsUploadProcessVo recordsUploadProcessVo)
    {
        return recordsService.recordsUploadProcess(recordsUploadProcessVo);
    }

    /**
     * 通过报名id获取档案详细信息进行补充上传
     * lqx
     */
//    @RequiresPermissions("training:records:query")
    @GetMapping("/upload-supplement/{registrationIds}")
    public List<RecordsUploadSupplementDto> selectRecordsByRegistrationIds(@PathVariable String[] registrationIds)
    {
        return recordsService.selectRecordsByRegistrationIds(registrationIds);
    }

    /**
     * 处理档案提交（新增、修改、删除）
     * @param frontSubmitDto 前端提交的数据
     * @return 处理结果
     * lqx
     */
//    @RequiresPermissions("training:records:add")
//    @Log(title = "档案", businessType = BusinessType.INSERT)
    @PostMapping("/addRecordsList")
    public AjaxResult handleRecordsSubmit(@RequestBody FrontSubmitDto frontSubmitDto) {
        return toAjax(recordsService.handleRecordsSubmit(frontSubmitDto));
    }

}
